from loguru import logger

from com.arcfox.base.base_spider import BaseSpider
from com.arcfox.middleware.async_redis_middleware import open_redis
from com.arcfox.util import util


class HandBaseSpider(BaseSpider):
    '''
    掌上高考(PC)爬虫基类
    '''

    def __init__(self):
        self.KEY = "D23ABC@#56"

    def get_sign_safe(self, url):
        '''
        获取signsafe参数
        :param url:
        :return:
        '''
        url = util.multi_replace(url, ['https://', 'http://'], "")
        v1 = util.hash_hmac_sha1(url, self.KEY)
        return util.get_md5(v1, 'UTF-8')

    @open_redis
    async def init_data_version(self, client):
        return await super().init_data_version(client)

    def get_province_map(self):
        province_map = {
            "11": "北京",
            "12": "天津",
            "13": "河北",
            "14": "山西",
            "15": "内蒙古",
            "21": "辽宁",
            "22": "吉林",
            "23": "黑龙江",
            "31": "上海",
            "32": "江苏",
            "33": "浙江",
            "34": "安徽",
            "35": "福建",
            "36": "江西",
            "37": "山东",
            "41": "河南",
            "42": "湖北",
            "43": "湖南",
            "44": "广东",
            "45": "广西",
            "46": "海南",
            "50": "重庆",
            "51": "四川",
            "52": "贵州",
            "53": "云南",
            "54": "西藏",
            "61": "陕西",
            "62": "甘肃",
            "63": "青海",
            "64": "宁夏",
            "65": "新疆",
        }
        return province_map


if __name__ == "__main__":
    url = "https://api.eol.cn/web/api/?admissions=&central=&department=&dual_class=&f211=&f985=&is_doublehigh=&is_dual_class=&keyword=&nature=&page=15&province_id=&ranktype=&request_type=1&school_type=&size=20&type=&uri=apidata/api/gk/school/lists"
    logger.info(HandBaseSpider().get_sign_safe(url))
